package com.mycjj.android.adapter;


import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.mycjj.android.R;
import com.mycjj.android.activity.CarNetworkFriendDetailActivity;
import com.mycjj.android.activity.CarNetworkThemeDetailActivity;
import com.mycjj.android.bean.CarNetworkCommentBean;

public class CarNetworkCommentAdapter extends TAdapter<CarNetworkCommentBean>{

	public CarNetworkCommentAdapter(Context mContext) {
		super(mContext);
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_carnetwork_comment, null);
			holder = new ViewHolder();
			holder.iv_pic = (ImageView) convertView.findViewById(R.id.iv_pic);
			holder.tv_name = (TextView)convertView.findViewById(R.id.tv_name);
			holder.tv_floor = (TextView)convertView.findViewById(R.id.tv_floor);
			holder.tv_time = (TextView)convertView.findViewById(R.id.tv_time);
			holder.tv_reply = (TextView)convertView.findViewById(R.id.tv_reply);
			holder.wv_title = (WebView)convertView.findViewById(R.id.wv_title);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		final CarNetworkCommentBean bean = mList.get(position);
//		imageLoader.displayImage(bean.getMember_avatar(), holder.iv_pic);
		imageLoader1.displayImage(bean.getMember_avatar(), holder.iv_pic,options,animateFirstListener);
		holder.tv_name.setText(bean.getMember_name());
		holder.tv_floor.setText((position+1)+"楼");
		holder.tv_time.setText(bean.getTime());
		
		//holder.wv_title.setText(bean.getReply_content());
		holder.wv_title.loadDataWithBaseURL("",
				bean.getReply_content(),
				"text/html", "UTF-8", "");
		
		holder.tv_reply.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				CarNetworkThemeDetailActivity activity = (CarNetworkThemeDetailActivity)mContext;
		        activity.showPopWindow(position);
				InputMethodManager inputMethodManager=(InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
		        inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
			}
		});
		
		holder.iv_pic.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext,CarNetworkFriendDetailActivity.class);
				intent.putExtra("id", bean.getMember_id());
				mContext.startActivity(intent);
			}
		});
		holder.tv_name.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext,CarNetworkFriendDetailActivity.class);
				intent.putExtra("id", bean.getMember_id());
				mContext.startActivity(intent);
			}
		});
		
		return convertView;
	}
	
	static class ViewHolder{
		ImageView iv_pic;
		TextView tv_name;
		TextView tv_floor;
		TextView tv_time;
		TextView tv_reply;
		WebView wv_title;
	}
}
